/*
 * equalizer.h
 * Created on August 30, 2007; 5:24 PM
 * by VRamadurai
 */
#ifndef _EQUALIZER_H_
#define _EQUALIZER_H_

#include "HsTypes.h"

#define EQ_REF_SCALE_SL	(14) //symbol lock
#define EQ_REF_SCALE	(9)  //preamble equalizer
#define EQ_REF_MULT    	(1<<EQ_REF_SCALE_SL)


#define ALPHA_FLOAT (0.5)

#define N_PRE 7 //equalizer precursor tap size
#define N_POST 7 //equalizer post cursor tap size

#define N_LE (N_PRE + N_POST + 1) // %total filter length
#define RXSIZE 32 //input rx samples at 2 times the chip rate

void eq_buffer_init(struct HS_Phy11bStr  *HS_Phy11bPtrTh);
void set_eq_ref_samples(struct HS_Phy11bStr *HS_Phy11bPtrTh, hs_int32_t offset);
void GetEqRef(struct HS_Phy11bStr  *HS_Phy11bPtrTh);

void
frac_energy(
            struct HS_Phy11bStr *HS_Phy11bPtrTh,
            hs_int16_t * restrict buff_LEr,
            hs_int16_t * restrict buff_LEi
        );

void
AdaptiveEqTapsInit(
                hs_int16_t *w_LEri
              );


void
AdaptiveEqInit(
                struct HS_Phy11bStr  *HS_Phy11bPtrTh,
                hs_int16_t *inbuff_LEri
              );


void
AdaptiveEqData(
            hs_int16_t * restrict buff_LEr,
            hs_int16_t * restrict buff_LEi,
            hs_int16_t * restrict w_LEr,
            hs_int16_t * restrict w_LEi,
            hs_int16_t * restrict output_eqr,
            hs_int16_t * restrict output_eqi,
            hs_int32_t in_len
         );

hs_int32_t
AdaptiveEqPreamble(
            hs_int16_t * restrict buff_LEr,
            hs_int16_t * restrict buff_LEi,
            hs_int16_t * restrict w_LEr,
            hs_int16_t * restrict w_LEi,
            hs_int16_t * restrict RefEq,
            hs_int16_t energy_fixed,
            hs_int32_t eq_in_index,
            hs_int32_t eq_count,
            hs_int32_t in_len
         );

hs_int32_t
AdaptiveEqPreamble_7_asm(
				hs_int16_t *buff_LEri,
				hs_int16_t *w_LEri,
				hs_int16_t *RefEq,
				hs_int32_t energy,
				hs_int32_t eq_count
			);

hs_int32_t
AdaptiveEqPreamble_11_4_asm(
				hs_int16_t *buff_LEri,
				hs_int16_t *w_LEri,
				hs_int16_t *RefEq,
				hs_int32_t energy,
				hs_int32_t eq_count
			);

void
AdaptiveEqData_16_asm(
			hs_int16_t *buff_LEri,
			hs_int16_t *w_LEri,
			hs_int16_t *eq_output
		);


void
AdaptiveEqData_11_asm(
			hs_int16_t *buff_LEri,
			hs_int16_t *w_LEri,
			hs_int16_t *eq_output
		);
hs_int32_t preamble_sync(hs_int16_t * restrict inR, hs_int16_t *ref);
//hs_int32_t preamble_sync_intr(hs_int16_t * restrict inR, hs_int16_t * restrict preamble_ref);
hs_int32_t preamble_sync_intr(hs_int16_t * restrict inR,hs_int16_t * restrict inQ, hs_int16_t * restrict preamble_ref);

extern hs_int16_t eq_preamble_sfd_ref_g[3168];
extern hs_int16_t eq_pream_sfd_ref[PREAMBLE_DOWNSAMPLE_REFSIZE]; //1584*2
extern hs_int16_t w_LEri[32];
extern hs_int16_t buff_LEri[2*(N_LE+RXSIZE)];

#endif
